package com.fantsey.event;

import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @date 2024/3/8 16:30
 * @author fanxin
 * @since 1.0
 */
@Component
public class EmailService {

    /**
    * 使用注解方式，监听时间
    * @param sendEvent: email事件
    */
    @EventListener(EmailSendEvent.class)
    @Async
    @Order(100)
    public void receiveEmail(EmailSendEvent sendEvent) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("注解监听方式1，收到邮件：" + sendEvent.getAddress() + "，" + sendEvent.getContent());
    }

    /**
     * 使用注解方式，监听时间
     * @param sendEvent: email事件
     */
//    @EventListener(EmailSendEvent.class)
//    @Async
//    @Order(1)
//    public void receiveEmail2(EmailSendEvent sendEvent) {
//        System.out.println("注解监听方式2，收到邮件：" + sendEvent.getAddress() + "，" + sendEvent.getContent());
//    }

}
